package com.zhentao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhentao.pojo.Appointment;
import com.zhentao.pojo.AppointmentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 预约挂号Mapper接口
 */
@Mapper
public interface AppointmentMapper extends BaseMapper<Appointment> {
    
    /**
     * 查询预约挂号列表（包含就诊人信息）
     */
    @Select("SELECT r.gid, r.uid, r.username, r.number, r.id_number, r.phone, " +
            "r.dept_id, r.type, r.cost, r.status, r.by_data, r.by_time, r.yy_time, " +
            "r.hospitalname, r.hospitaladdress, r.doctor_id " +
            "FROM t_register r " +
            "ORDER BY r.yy_time DESC")
    List<AppointmentVO> selectAppointmentList();
    
    /**
     * 根据ID查询预约挂号详情
     */
    @Select("SELECT r.gid, r.uid, r.username, r.number, r.id_number, r.phone, " +
            "r.dept_id, r.type, r.cost, r.status, r.by_data, r.by_time, r.yy_time, " +
            "r.hospitalname, r.hospitaladdress, r.doctor_id " +
            "FROM t_register r " +
            "WHERE r.gid = #{id}")
    AppointmentVO selectAppointmentById(Integer id);
    
    /**
     * 根据就诊人ID查询预约挂号列表
     */
    @Select("SELECT r.gid, r.uid, r.username, r.number, r.id_number, r.phone, " +
            "r.dept_id, r.type, r.cost, r.status, r.by_data, r.by_time, r.yy_time, " +
            "r.hospitalname, r.hospitaladdress, r.doctor_id " +
            "FROM t_register r " +
            "WHERE r.uid = #{patientId} " +
            "ORDER BY r.yy_time DESC")
    List<AppointmentVO> selectAppointmentsByPatientId(Integer patientId);
    
    /**
     * 根据状态查询预约挂号列表
     */
    @Select("SELECT r.gid, r.uid, r.username, r.number, r.id_number, r.phone, " +
            "r.dept_id, r.type, r.cost, r.status, r.by_data, r.by_time, r.yy_time, " +
            "r.hospitalname, r.hospitaladdress, r.doctor_id " +
            "FROM t_register r " +
            "WHERE r.status = #{status} " +
            "ORDER BY r.yy_time DESC")
    List<AppointmentVO> selectAppointmentsByStatus(Integer status);
} 